<template>
  <el-container>
    <basic-crud v-model="formData" :option="option" ref="basicCrudRef"
      businessUrl="/obj/attributeController"></basic-crud>
  </el-container>
</template>

<script setup>
import { onlyEnglish } from '@/utils/regexp.js'
const formData = ref({})
const basicCrudRef = ref()
const option = {
  viewBtn: true,
  searchSpan: 6,
  menuWidth: 180,
  column: [
    {
      label: '属性英文名称',
      prop: 'code',
      search: true,
      width: 150,
      maxlength: 20,
      showWordLimit: true,
      placeholder: '只能输入英文，建议以驼峰方式命名，切勿输入拼音',
      rules: [
        { required: true, message: '属性英文名称不能为空', trigger: 'blur' },
        {
          pattern: onlyEnglish,
          message: '只能输入英文字符',
          trigger: ['change', 'blur'],
        },
      ],
    },
    {
      label: '属性中文名称',
      prop: 'name',
      width: 180,
      search: true,
      overHidden: true,
      sortable: true,
      rules: [
        { required: true, message: '属性中文名称不能为空', trigger: 'blur' },
      ],
    },
    {
      label: '对象里属性',
      prop: 'objCode',
      width: 120,
      search: true,
      placeholder: '在持久化的对象里的属性，开发人员使用,默认等于英文名称',
      sortable: true,
    },
    {
      label: '属性类型',
      prop: 'attributeDataType',
      width: 120,
      search: true,
      sortable: true,
      type: 'select',
      value: 'String',
      rules: [{ required: true, message: '属性类型不能为空', trigger: 'blur' }],
      dicData: [
        {
          label: '字符串',
          value: 'String',
        },
        {
          label: '整形',
          value: 'Integer',
        },
        {
          label: '长整形',
          value: 'Long',
        },
        {
          label: '金额/双精度',
          value: 'Double',
        },
        {
          label: '开关/是否',
          value: 'Boolean',
        },
        {
          label: '日期',
          value: 'Date',
        },
        {
          label: '日期时间',
          value: 'DateTime',
        },
        {
          label: '时间',
          value: 'Time',
        },
        {
          label: '超长文本',
          value: 'Clob',
        },
        {
          label: '文件',
          value: 'File',
        },
      ],
    },
    {
      label: '可空',
      prop: 'nullableFlag',
      type: 'switch',
      value: 'true',
      width: 80,
      rules: [{ required: true, message: '是否可空必须选择', trigger: 'blur' }],
      enumCode: 'trueFalseDic',
    },
    {
      label: '默认值',
      prop: 'defaultValue',
      width: 100,
    },
    {
      label: '枚举类型',
      prop: 'enumName',
      search: true,
      overHidden: true,
      width: 160,
      component: 'BasicCrudTableSelect',
      dataType: 'enum',
      comProps: {
        saveFieldMap: { enumName: 'name', enumCode: 'code' },
        selectedKey: 'code',
      },
      curForm: formData,
      change: (val) => {
        formData.value = val
      }
    },
    {
      label: '引用类型',
      prop: 'busReferName',
      search: true,
      width: 160,
      overHidden: true,
      placeholder: '选择属性引用的业务类型',
      sortable: true,
      formatter: (row) => {
        return row?.busReferName
      },
      component: 'BasicCrudTableSelect',
      dataType: 'bus',
      comProps: {
        saveFieldMap: { busReferName: 'name', busCode: 'code' },
        selectedKey: 'code',
      },
      curForm: formData,
      change: (val) => {
        formData.value = val
      }
    },
    {
      label: '长度',
      prop: 'attributeLength',
      type: 'number',
      width: 90,
      step: 10,
      value: 50,
      tip: '整形，长整形，超长文本，开关类型的时候，后台会自动默认长度，页面输入的无效',
      clearable: true,
    },
    {
      label: '小数精度',
      prop: 'precisionLength',
      type: 'number',
      width: 90,
      tip: '金额/双精度的时候，小数精度必须要填写，否则系统默认为2',
      clearable: true,
    },
    {
      label: '描述',
      prop: 'des',
      type: 'textarea',
      span: 24,
    },
  ],
}
</script>

<style lang="scss" scoped></style>
